package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.T100WcSttm;
import com.ruoyi.system.domain.vo.T100WcSttmVo;
import com.ruoyi.system.service.T100WcSttmService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报工明细Controller
 * 
 * @author AHan
 * @date 2024-07-31
 */
@Controller
@RequestMapping("/system/sttm")
public class T100WcSttmController extends BaseController
{
    private String prefix = "system/sttm";

    @Autowired
    private T100WcSttmService t100WcSttmService;

    @RequiresPermissions("system:sttm:view")
    @GetMapping()
    public String t100wcsttm()
    {
        return prefix + "/sttm";
    }

    /**
     * 查询报工明细列表
     */
    @RequiresPermissions("system:sttm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(T100WcSttmVo t100wcsttmvo)
    {
        startPage();
        List<T100WcSttmVo> list = t100WcSttmService.selectT100wcsttmList(t100wcsttmvo);
/*        for (T100WcSttm sttm : list) {
            System.out.println(sttm.toString());
        }*/
        return getDataTable(list);
    }

    /**
     * 导出报工明细列表
     */
    @RequiresPermissions("system:sttm:export")
    @Log(title = "报工明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(T100WcSttmVo t100wcsttmvo)
    {
        List<T100WcSttmVo> list = t100WcSttmService.selectT100wcsttmList(t100wcsttmvo);
        ExcelUtil<T100WcSttmVo> util = new ExcelUtil<T100WcSttmVo>(T100WcSttmVo.class);
        return util.exportExcel(list, "报工明细数据");
    }

    /**
     * 新增报工明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报工明细
     */
    @RequiresPermissions("system:sttm:add")
    @Log(title = "报工明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(T100WcSttm t100wcsttm)
    {
        return toAjax(t100WcSttmService.insertT100wcsttm(t100wcsttm));
    }

    /**
     * 修改报工明细
     */
    @RequiresPermissions("system:sttm:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String STTMDOCNO, ModelMap mmap)
    {
        System.out.println(STTMDOCNO);
        int STTMDOCNO2 = Integer.parseInt(STTMDOCNO);
        T100WcSttm sttm = t100WcSttmService.selectT100wcsttmBySTTMDOCNO(STTMDOCNO2);
        mmap.put("sttm", sttm);
        return prefix + "/edit";
    }

    /**
     * 修改保存报工明细
     */
    @RequiresPermissions("system:sttm:edit")
    @Log(title = "报工明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(T100WcSttm t100wcsttm)
    {
        return toAjax(t100WcSttmService.updateT100wcsttm(t100wcsttm));
    }

    /**
     * 删除报工明细
     */
    @RequiresPermissions("system:sttm:remove")
    @Log(title = "报工明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(t100WcSttmService.deleteT100wcsttmBySTTMDOCNOs(ids));
    }
}
